package com.orange.core.pojo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>ClassName:PaymentTypeEnums</p>
 * <p>Description: 活动收费枚举</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/7/11 13:29</p>
 */
@AllArgsConstructor
@Getter
public enum PaymentTypeEnums implements Serializable {

    FREE(0, "免费"),
    POINTS(1, "积分"),
    MONEY(2, "微信支付");

    @EnumValue
    private Integer code;

    @JsonValue
    private String desc;


    private static final Map<Integer, PaymentTypeEnums> CODE_TO_MENUM_MAP = Arrays.stream(values())
            .collect(Collectors.toUnmodifiableMap(PaymentTypeEnums::getCode, e -> e));

    public  static PaymentTypeEnums getByCode(Integer code) {
        PaymentTypeEnums paymentTypeEnums = CODE_TO_MENUM_MAP.get(code);
        if (paymentTypeEnums == null) {
            throw new IllegalArgumentException("无效的code值：" + code);
        }
        return paymentTypeEnums;
    }
}
